<template>
    <el-dialog v-model="dialogVisible" :title="`审核-${bodyData.id}`" width="800px">
        <el-form :model="bodyData" ref="form" label-position="top" label-width="300px">
            <el-scrollbar height="600px" class="box-body">

                <el-form-item label="帖子ID" prop="groupCode">
                    <el-input size="large" :disabled="true" v-model="bodyData.id"></el-input>
                </el-form-item>

                <el-form-item label="审核状态" prop="auditStatusCode">
                    <el-select :disabled="true" style="width: 100%;" v-model="bodyData.auditStatusCode"
                        placeholder="请选择审核状态">
                        <el-option v-for="item in auditStatusCodeList" :key="item.code" :label="item.label"
                            :value="item.value">
                        </el-option>
                    </el-select>
                </el-form-item>

                <!-- 内容 -->
                <el-form-item label="内容" prop="content">
                    <el-input size="large" :disabled="true" :autosize="true" type="textarea" v-model="bodyData.content"
                        placeholder="没有内容"></el-input>
                </el-form-item>

                <!-- 图片 -->
                <el-form-item label="图片" prop="image">
                    <div style="text-align: center;">
                        <div v-if="bodyData.imageList.length == 0">无</div>
                        <div v-for="(item, index) in bodyData.imageList" :key="index" style="text-align: center;">
                            <div style="font-size: 30rpx;">第{{ index + 1 }}张</div>
                            <el-image :src="$kt.file.visit(item.fileId)" :z-index="999" :preview-teleported="true"
                                :initial-index="1" fit="cover" style="width: 60%" />
                        </div>
                    </div>
                </el-form-item>

            </el-scrollbar>

        </el-form>
        <div style="height: 20px;"></div>
        <span class="dialog-footer">
            <el-button @click="close">取 消</el-button>
            <el-button type="danger" @click="reject">审核不通过</el-button>
            <el-button type="primary" @click="pass">审核通过</el-button>
        </span>
        <div style="height: 20px;"></div>

        <el-dialog v-model="dialogVisibleOfReject" title="Tips" width="30%">
            <div style="text-align: center;">
                <!-- 输入审核不通过的原因 -->
                <el-form :model="requestParam" ref="form" label-position="top" label-width="300px">
                    <el-form-item label="审核不通过的原因" prop="rejectReason">
                        <el-input size="large" :autosize="true" type="textarea" v-model="requestParam.auditRejectReason"
                            placeholder="请输入审核不通过的原因"></el-input>
                    </el-form-item>
                </el-form>
            </div>

            <template #footer>
                <span class="dialog-footer">
                    <el-button @click="dialogVisibleOfReject = false">取消</el-button>
                    <el-button type="primary" @click="dialogVisibleOfReject = false;submit();">
                        确定
                    </el-button>
                </span>
                <div style="height: 30px;"></div>
            </template>
        </el-dialog>

    </el-dialog>
</template>

<script lang="ts" setup>
import { ref, defineExpose, defineEmits } from 'vue';
import $kt from '@/vueKantboot';
import { ElMessage } from 'element-plus';

let dialogVisible = ref(false);

let dialogVisibleOfReject = ref(false);

let groups = ref([{
    code: "1",
    name: "1"
}]);


/**
 * 审核状态编码
 * 待审核 wait
 * 审核通过 pass
 * 审核不通过 reject
 * 审核中 ing
 * 审核异常 error
 */
let auditStatusCodeMap = ref({
    wait: '待审核',
    pass: '审核通过',
    reject: '审核不通过',
    ing: '审核中',
    error: '审核异常',
});

// 将map转换为数组
let auditStatusCodeList = ref(Object.keys(auditStatusCodeMap.value).map((key) => {
    return {
        label: auditStatusCodeMap.value[key],
        value: key,
    }
}));


let bodyData = ref({
    "adCode": "330109",
    "adCodeOfSelect": "330109",
    "auditStatusCode": "wait",
    "city": "杭州市",
    "cityOfSelect": "杭州市",
    "content": "归云一去无踪迹，\n何处是前期？\n狎兴生疏，\n酒徒萧索，\n不似少年时。",
    "district": "萧山区",
    "districtOfSelect": "萧山区",
    "gmtCreate": 1688316935662,
    "gmtModified": 1688316935662,
    "id": 434915467927557,
    "imageList": [

    ],
    "latitude": 30.18534,
    "latitudeOfSelect": 30.18534,
    "longitude": 120.26457,
    "longitudeOfSelect": 120.26457,
    "ovoUser": {
        "emotionalOrientationList": [

        ],
        "gmtCreate": 1688316702500,
        "gmtModified": 1688316702504,
        "introduction": "0000",
        "location": {
            "adCode": "330109",
            "city": "杭州市",
            "country": "中国",
            "countryCode": "156",
            "district": "萧山区",
            "gmtCreate": 1688316703094,
            "gmtModified": 1688316703094,
            "gmtTencentMapApiTime": 1688316705854,
            "latitude": 30.18534,
            "longitude": 120.26457,
            "province": "浙江省",
            "userId": 434914406531077
        },
        "sadomasochismAttrCode": "sado",
        "sexualOrientationCode": "male",
        "user": {
            "birthday": 1104508800000,
            "fileIdOfAvatar": 434914510573573,
            "gender": 0,
            "gmtCreate": 1688316676532,
            "gmtModified": 1688316702494,
            "id": 434914406531077,
            "nickname": "9999",
            "roles": [

            ]
        },
        "userId": 434914406531077
    },
    "province": "浙江省",
    "provinceOfSelect": "浙江省",
    "userId": 434914406531077,
    "visibleCode": "all"
});

let close = () => {
    dialogVisible.value = false;
}

let open = (item: any) => {
    bodyData.value = item;
    requestParam.value.auditRejectReason = "";
    requestParam.value.id = item.id;
    console.log(item);
    dialogVisible.value = true;
}


let requestParam = ref({
    id: 0,
    auditStatusCode: "reject",
    auditRejectReason: "",
});

let pass = () => {
    requestParam.value.auditStatusCode = "pass";
    submit();
}

let reject = () => {
    dialogVisibleOfReject.value = true;
    requestParam.value.auditStatusCode = "reject";
}

const emits = defineEmits(["flush"]);
let submit = () => {

    $kt.request.request({
        url: '/adminManage/business/ovo/post/audit',
        method: 'post',
        data: requestParam.value
    }).then((res: any) => {
        if (res.data.state != 2000) {
            ElMessage({
                message: res.data.errMsg,
                type: 'error',
            });
            return false;
        }
        ElMessage({
            message: res.data.msg,
            type: 'success',
        });



        close();
        emits("submit");
    });
}

defineExpose({
    open,
    close
});
</script>

<style lang="scss" scoped>
.dialog-footer {
    float: right;
}
</style>